﻿<%@ Page Title="" Language="C#" MasterPageFile="~/administrator/backend.Master" AutoEventWireup="true"
    CodeBehind="advertisements-add.aspx.cs" Inherits="VQWEB.administrator.advertisements.advertisements_add" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Content_backend" runat="server">
     <form id="frmObjects" action="" method="post">
    </form>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Script_backend" runat="server">
    <script type="text/javascript">
        ShowToolBar("edit");
        var url_ashx = "/admin/advertisement/handler";
        var url_input = '<%=ResolveUrl("~/administrator/templates/input.tpl") %>';

        $(document).ready(function () {
            if (CheckAtionInPath("add")) {
                loadform(0, "", "", "", "", false);
            }
            else if (CheckAtionInPath("edit")) {
                $.get(url_ashx, { view_advertisement: "view_advertisement", Id: GetId() }, function (data) {
                    var obj = $.parseJSON(data);
                    loadform(obj.id, obj.img, obj.width, obj.height, obj.embed,obj.active);
                });
            }

        });

        function loadform(id, img, width, height, embed, active) {
            $.jqoteload(url_input, function (tmpl) {

                $("#frmObjects").single("hidden", "advertisement_id", id, null, null, tmpl.input_tpl);
                $("#frmObjects").single("text", "advertisement_img", img, "Hình ảnh:", null, tmpl.input_tpl);
                $("#frmObjects").single("text", "advertisement_width", width, "Chiều rộng:", null, tmpl.input_tpl);
                $("#frmObjects").single("text", "advertisement_height", height, "Chiều cao:", null, tmpl.input_tpl);
                $("#frmObjects").single("text", "advertisement_embed", embed, "Mã nhúng:", null, tmpl.input_tpl);
                $("#frmObjects").single("checkbox", "advertisement_active", true, "Kich hoat", active, tmpl.input_tpl);
            });
        }

        $(document).on("click", "#btnCancel", function () {
            window.location = "/admin/advertisement/list";
        });
        $(document).on("click", "#btnSave", function () {
            var arr = $("#frmObjects").serializeObject();
            $.post(url_ashx, { add_advertisement: window.escape(arr) }, function (data) {
                alert(data);
                window.location = "/admin/advertisement/list";
            });
        });
    </script>
</asp:Content>
